package com.czy.owner.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.TestingDetailsModel;
import com.czy.owner.entity.TextingListModel;
import com.czy.owner.utils.StringUtils;
import com.czy.owner.utils.TimeUtils;
import com.czy.owner.utils.glide.GlideUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hedepu on 2017/10/31 0001.
 */
public class TestingRecommendAdapter extends RecyclerArrayAdapter<TestingDetailsModel.OrderItemModel> {

    private Context context;

    public TestingRecommendAdapter(Context context) {
        super(context);
        this.context = context;
    }


    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new TestingRecommendHolder(parent);
    }

    class TestingRecommendHolder extends BaseViewHolder<TestingDetailsModel.OrderItemModel> {


        @BindView(R.id.iv_texting_img)
        ImageView ivTextingImg;
        @BindView(R.id.tv_name)
        TextView tvName;


        @BindView(R.id.linear_bottom)
        LinearLayout linearBottom;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.tv_distance)
        TextView tvDistance;

        public TestingRecommendHolder(ViewGroup parent) {
            super(parent, R.layout.item_testing_recommend_recycler);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void setData(final TestingDetailsModel.OrderItemModel data) {
            super.setData(data);
            tvName.setText(getText(data.getItemName()));
            if (StringUtils.isEmpty(data.getSpecValue()) || "规格:无规格".equals(data.getSpecValue())) {
                tvTime.setText("");
            } else {
                tvTime.setText(data.getSpecValue());
            }
            tvDistance.setText("¥" + data.getPrice());
            if ("service".equals(data.getItemType())) {
                tvTime.setVisibility(View.GONE);
                GlideUtils.loadImage(getContext(), data.getLogo(), ivTextingImg, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                    @Override
                    public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                    }

                    @Override
                    public void onLoadingError(String source, Exception e) {

                    }
                }, R.mipmap.default_icon, R.mipmap.default_icon);
            } else if ("goods".equals(data.getItemType())) {
                GlideUtils.loadImage(getContext(), StringUtils.isEmpty(data.getLogo()) ? data.getGoodsLogo() : data.getLogo(), ivTextingImg, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                    @Override
                    public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                    }

                    @Override
                    public void onLoadingError(String source, Exception e) {

                    }
                }, R.mipmap.default_icon, R.mipmap.default_icon);
            }

        }
    }

    public String getText(String text) {
        if (text.length() <= 16) {
            return text;
        } else {
            return text.substring(0, 16) + "...";
        }

    }

}
